<?php
/*
----------------------------------------
-----    Page logic description    -----
----------------------------------------
REFERENCES FROM:
    * cp__mon.php (as include)
INPUT:
    m       => monitor object
OUTPUT: 
	Page
----------------------------------------
*/

if (!isset($account)) {
    die("Access denied."); // TODO: make as a function
}    

if (!isset($m)) {
    die("Access denied."); // TODO: make as a function
}

$monitor = $m;
?>

<form name="form_monitor_<?=$monitor->id?>">
<input type="hidden" name="mid" value="<?=$monitor->id?>">


<!-- GENERAL SETTINGS -->
<table border="0" cellspacing="2" cellpadding="0" width="800" style="margin-top: 3; cursor:pointer;">
<tr>
	<td class="tdH" onMouseOver="this.className='tdH2'" onMouseOut="this.className='tdH'" onclick="ShowSettingGroup(1,<?=$monitor->id?>)"><img id="setimg_1_<?=$monitor->id?>" src="/images/arrow_up.gif">&nbsp;&nbsp;&nbsp;General</td>
</tr>
</table>

<div id="settings_1_<?=$monitor->id?>" style="">


<table border="0" cellspacing="0" cellpadding="0">
<tr><td valign="top" width="410">


<table border="0" cellspacing="2" cellpadding="0" style="">
<tr>
	<td><span class="text">URL:</td>
	<td><span class="text"><input type="Edit" name="f_url" value="<?=htmlspecialchars(@$monitor->data["url"])?>" 
        class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width: 350; "></td>
</tr>
<tr>
	<td><span class="text">Name:</td>
	<td><span class="text"><input type="Edit" name="f_title" value="<?=htmlspecialchars(@$monitor->data["title"])?>" 
        class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width: 350;"></td>
</tr>
<tr>
	<td><span class="text">Category:</td>
	<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td><span class="text">
        <select name="f_category_id" style="width: 150;">
            class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" 
        <? html_options_from_map($categories->names, $monitor->data["category_id"]); ?>
        </select></td>
	<td><span class="text">
        &nbsp;or&nbsp;new:&nbsp;</td>
	<td><span class="text">
        <input type="Text" name="f_category_new_name"  value="<?=htmlspecialchars(@$f_category_new_name)?>" style="width: 148;"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'"></td>
</tr>
</table>
        </td>
</tr>
<tr>
	<td><span class="text">Periodicity:</td>
	<td><span class="text"><select name="f_frequency" style="width:150"
            class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'">
		<? html_options_from_map($g_monitor_frequency_map, $monitor->data["frequency"]); ?>
		</select></td>
</tr>
</table>
        
<p class="text">
<?php
$v = @$monitor->data["alert_type"];
$mid = $monitor->id;
include $r."members/cp__mon_det__at.php";
?>

    
</td><td valign="top" style="padding-left: 25;">

<?
$r = GetLastChangedItem($monitor->id);
if ($r) {
?>
<p class="text" style="color: #333333;">Last changed: 
    <b><?=$r["dt"]?></b>
    [ <a href="<?=$r["href"]?>">show changes highlighted</a> ]
</p>
<? } ?>

<?
if (@$monitor->data["last_alert"] != "" &&
	@$monitor->data["last_alert"] != "0000-00-00 00:00:00")
{
	$s = date('M j \a\t g A', strtotime($monitor->data["last_alert"]));
?>
<p class="text" style="color: #333333;">
    Notification: <b>Alert e-mail sent on <?=$s?></b>
</p>
<? } ?>


<?php include "cp__mon_det__history_t.php"; ?>
    
<?
$row = GetFirstMonitoredItem($monitor->id); 
if ($row) {
?>
<p class="text">
    [+] Monitored since <?=date("M d, Y", strtotime($row["download_dt"]))?> 
    [ <a href="history_nav.php?monitor_id=<?=$monitor->id?>&resource_id=<?=$row["id"]?>">show monitoring archive</a> ]
</p>
<? } ?>

</td><td>

</td></tr>
</table>

</div>


<!-- MONITORING SETTINGS -->
<table border="0" cellspacing="2" cellpadding="0" width="800" style="margin-top: 3; cursor:pointer;">
<tr>
	<td class="tdH" onMouseOver="this.className='tdH2'" onMouseOut="this.className='tdH'" onclick="ShowSettingGroup(2,<?=$monitor->id?>)"><img id="setimg_2_<?=$monitor->id?>" src="/images/arrow_down.gif">&nbsp;&nbsp;&nbsp;Advanced Options</td>
</tr>
</table>

<div id="settings_2_<?=$monitor->id?>" style="display:none">

<table border="0" cellspacing="5" cellpadding="0" width="100%" 
    style=""
    id="idMonDivExt_<?=$monitor->id?>">


<? $tr_i = 0; ?>


<tr id="tr_<?=(++$tr_i)?>">
	<td></td>
	<td colspan="2"><span class="textStd">
		<?
		$trigger_type = @$monitor->data["trigger_type"]; 
		$v = $trigger_type & TRIGGER_TYPE_MASK;
		foreach ($g_trigger_type_map as $k => $txt)
		{
			echo '<input type="Radio" name="f_trigger_type" ';
			html_radio_value($k, $v);
			echo '>'.$txt."<br>\n";
		}
		?>
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td valign="top"><span class="text">Keywords:</td>
	<td><span class="textStd"><textarea rows="3" name="f_trigger_params"
			style="width: 230;" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'"
			><?=htmlspecialchars(@$monitor->data["trigger_params"])?></textarea></td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td valign="top"><span class="text">Flags:</td>
	<td colspan="2"><span class="textStd">
		<input type="Radio" name="f_trigger_type_search_text"
			<? html_radio_value(TRIGGER_FLAG_IN_ADD_TEXT, $trigger_type & TRIGGER_FLAG_SEARCH_TEXT); ?>>
		In addition
		<input type="Radio" name="f_trigger_type_search_text"
			<? html_radio_value(TRIGGER_FLAG_IN_DEL_TEXT, $trigger_type & TRIGGER_FLAG_SEARCH_TEXT); ?>>
		In deletion
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td></td>
	<td><span class="textStd"><input type="Checkbox" name="f_trigger_type_skip_digits"
		<? html_radio_value(TRIGGER_FLAG_SKIP_DIGITS, $trigger_type & TRIGGER_FLAG_SKIP_DIGITS); ?>>
		Skip digits</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td></td>
	<td><span class="textStd"><input type="Checkbox" name="f_trigger_type_skip_sm_ch"
		<? html_radio_value(TRIGGER_FLAG_SKIP_SMALL_CHANGES, $trigger_type & TRIGGER_FLAG_SKIP_SMALL_CHANGES); ?>>
		Skip small changes</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Status:</td>
	<td colspan="2"><span class="textStd">
		<? $v = @$monitor->data["status"] & MONITOR_STATUS_IS_ACTIVE_MASK; ?>
		<input type="Radio" name="f_status_is_active" <? html_radio_value(MONITOR_STATUS_IS_ACTIVE_MASK, $v); ?>> Active
		<input type="Radio" name="f_status_is_active" <? html_radio_value(0,  $v); ?>> Paused
	</td>
</tr>
<input type="Hidden" name="f_xpath" value="<?=htmlspecialchars(@$monitor->data["xpath"])?>">
<?/*
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">X-Path:</td>
	<td><span class="textStd"><input type="Text" name="f_xpath" value="<?=htmlspecialchars(@$monitor->data["xpath"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
*/?>


<tr id="tr_<?=(++$tr_i)?>">
	<td colspan="2">&nbsp;</td>
</tr>

</table>
</div>

<!-- scheduling SETTINGS -->
<table border="0" cellspacing="2" cellpadding="0" width="800" style="margin-top: 3; cursor:pointer;">
<tr>
	<td class="tdH" onMouseOver="this.className='tdH2'" onMouseOut="this.className='tdH'" onclick="ShowSettingGroup(3,<?=$monitor->id?>)"><img id="setimg_3_<?=$monitor->id?>" src="/images/arrow_down.gif">&nbsp;&nbsp;&nbsp;Notifications & Scheduling</td>
</tr>
</table>

<div id="settings_3_<?=$monitor->id?>" style="display:none">

<table border="0" cellspacing="5" cellpadding="0" width="100%" 
    style=""
    id="idMonDivExt_<?=$monitor->id?>">


<? $tr_i = 0; ?>

<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Notification E-mail(s):</td>
	<td><span class="textStd"><input type="Text" name="f_alert_emails" value="<?=htmlspecialchars(@$monitor->data["alert_emails"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td></td>
	<td><span class="textStd">Separate e-mails with commas to alert on several 
		addresses simultaneously</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Monitor at time:</td>
	<td><span class="textStd">
		<input type="hidden" id ="id_f_monitor_at_time" name="f_monitor_at_time" value="<?=htmlspecialchars(@$monitor->data["monitor_at_time"])?>">
		<? print_time_control(@$monitor->data["monitor_at_time"], "f_monitor_at_time"); ?>
	</td>
</tr>

<tr id="tr_<?=(++$tr_i)?>">
	<td valign="top"><span class="text">Alert at time:</td>
	<td><span class="textStd">
		<? 
		$t = @$monitor->data["alert_at_time"]; 
		$tf = (@$t >= 0 ? 1 : 0);
		?>

		<input type="Radio" name="f_alert_at_time_flag"
		<? html_radio_value(0, $tf); ?> onClick="aat_type_changed(false)">
		Immediately<br>
		
		<input type="Radio" name="f_alert_at_time_flag"
		<? html_radio_value(1, $tf); ?> onClick="aat_type_changed(true)">
		Inform at

		<input type="hidden" id="id_f_alert_at_time" name="f_alert_at_time" value="<?=($t >= 0 ? $t : 0)?>">
		<? print_time_control(@$monitor->data["alert_at_time"], "f_alert_at_time"); ?>
	</td>
</tr>
<script type="text/javascript" language="JavaScript">
function aat_type_changed(en)
{
	f.f_alert_at_time_h.disabled = !en;
	f.f_alert_at_time_m.disabled = !en;
}
aat_type_changed(<?=($tf ? "true" : "false")?>);
</script>

<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Reference URL:</td>
	<td><span class="textStd"><input type="Text" name="f_reference_url" value="<?=htmlspecialchars(@$monitor->data["reference_url"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<input type="hidden" name="f_enable_history" value="1">


<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Highlighted Text Color:</td>
	<td><span class="textStd"><select name="f_highlight_font_color" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'"
		onChange="update_hl_ex(<?=$monitor->id?>);" style="width:100">
		<? html_options_from_map($g_hightlight_font_color_map, @$monitor->data["highlight_font_color"]); ?>
		</select>
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Highlighted Text Background:</td>
	<td><span class="textStd"><select name="f_highlight_bk_color" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'"
		onChange="update_hl_ex(<?=$monitor->id?>);" style="width:100">
		<? html_options_from_map($g_hightlight_bk_color_map, @$monitor->data["highlight_bk_color"]); ?>
		</select>
        
		Highlight
        <span id="hl_ex_<?=$monitor->id?>"><span id="hl_ex2_<?=$monitor->id?>">
        changes</span></span>
        and
        <span id="hl_exi_<?=$monitor->id?>"><span id="hl_exi2_<?=$monitor->id?>">
        keywords</span></span>
        
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Highlighted Text Style:</td>
	<td><span class="textStd">
	<? 
	$v = @$monitor->data["highlight_font_style"];
	foreach ($g_highlight_font_style_map as $k => $name) 
	{ 
		echo '<input type="Checkbox" name="f_hl_fs_'.$k.'" onClick="update_hl_ex('.$monitor->id.');" ';
		html_radio_value($k, $v & $k);
		echo '>'.$name."\n";
	} 
	?>
	</td>
</tr>

</table>
</div>


<!-- AUTH SETTINGS -->
<table border="0" cellspacing="2" cellpadding="0" width="800" style="margin-top: 3; cursor:pointer;">
<tr>
	<td class="tdH" onMouseOver="this.className='tdH2'" onMouseOut="this.className='tdH'" onclick="ShowSettingGroup(4,<?=$monitor->id?>)"><img id="setimg_4_<?=$monitor->id?>" src="/images/arrow_down.gif">&nbsp;&nbsp;&nbsp;Authorization & Proxy</td>
</tr>
</table>

<div id="settings_4_<?=$monitor->id?>" style="display: none">
     
<table border="0" cellspacing="5" cellpadding="0" width="100%" 
    style=""
    id="idMonDivExt_<?=$monitor->id?>">

<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Page Character Encoding:</td>
	<td><span class="textStd"><select name="f_user_charset" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" 
        style="width: 150">
		    <? html_options_from_map($g_charset_map, @$monitor->data["user_charset"]); ?>
		</select>
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">User-Agent:</td>
	<td><span class="textStd"><select name="f_http_user_agent_type" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" 
        style="width:150">
		    <? html_options_from_map($g_http_user_agent_type_map, @$monitor->data["http_user_agent_type"]); ?>
		</select>
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">User-Agent Custom:</td>
	<td><span class="textStd"><input type="Text" name="f_http_user_agent_custom" value="<?=htmlspecialchars(@$monitor->data["http_user_agent_custom"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">HTTP Auth User:</td>
	<td><span class="textStd"><input type="Text" name="f_http_auth_user" value="<?=htmlspecialchars(@$monitor->data["http_auth_user"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">HTTP Auth Password:</td>
	<td><span class="textStd"><input type="Password" name="f_http_auth_password" value="<?=htmlspecialchars(@$monitor->data["http_auth_password"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td valign="top"><span class="text">Cookies:</td>
	<td><span class="textStd"><textarea rows="3" name="f_http_cookies"
			style="width: 230;" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'"
			><?=htmlspecialchars(@$monitor->data["http_cookies"])?></textarea></td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td valign="top"><span class="text">Form Post Content:</td>
	<td><span class="textStd"><textarea rows="3" name="f_http_form_content"
			style="width: 230;" class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'"
			><?=htmlspecialchars(@$monitor->data["http_form_content"])?></textarea></td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Proxy Address:</td>
	<td><span class="textStd"><input type="Text" name="f_proxy_addr" value="<?=htmlspecialchars(@$monitor->data["proxy_addr"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Proxy Port:</td>
	<td><span class="textStd"><input type="Text" name="f_proxy_port" id="id_proxy_port" value="<?=htmlspecialchars(@$monitor->data["proxy_port"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Proxy Auth User:</td>
	<td><span class="textStd"><input type="Text" name="f_proxy_auth_user" value="<?=htmlspecialchars(@$monitor->data["proxy_auth_user"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
<tr id="tr_<?=(++$tr_i)?>">
	<td><span class="text">Proxy Auth Password:</td>
	<td><span class="textStd"><input type="Password" name="f_proxy_auth_password" value="<?=htmlspecialchars(@$monitor->data["proxy_auth_password"])?>"
			class="input2" onFocus="this.className='input2_act'" onBlur="this.className='input2'" style="width:230">
	</td>
</tr>
</table>

</div>

<!-- BUTTONS -->


<p class="text">
<!--
<input type="Button" value="Edit advanced monitor settings &gt;" style="width: 268;" id="idEditAdvMonSet_<?=$monitor->id?>"
    class="button2" onMouseOver="this.className='button2_act'" onMouseOut="this.className='button2'"
    onClick="do_show_advanced(<?=$monitor->id?>); return false;">
-->

<p class="text">
<input type="Button" value="Save" style="width: 50;"
    class="button2" onMouseOver="this.className='button2_act'" onMouseOut="this.className='button2'"
    onClick="do_save_monitor(<?=$monitor->id?>, false); return false;">

<input type="Button" value="Save & Add Another" style="width: 150;"
    class="button2" onMouseOver="this.className='button2_act'" onMouseOut="this.className='button2'"
    onClick="do_save_monitor(<?=$monitor->id?>, true); return false;">

<input type="Button" value="Cancel" style="width: 60;"
    class="button2" onMouseOver="this.className='button2_act'" onMouseOut="this.className='button2'"
    onClick="do_cancel_monitor(<?=$monitor->id?>); return false;">

<?/*
<!--p class="text"-->
<a href="" onClick="do_show_advanced(<?=$monitor->id?>); return false;">
    Edit advanced monitor settings <span id="idEditAdvMonSetArrow_<?=$monitor->id?>">&gt;</span></a>

<br>

<!--a href="" onClick="do_save_monitor(<?=$monitor->id?>, false); return false;">
    Save</a> | 
<a href="" onClick="do_save_monitor(<?=$monitor->id?>, true); return false;">
    Save & Add Another</a> | 
<a href="" onClick="do_cancel_monitor(<?=$monitor->id?>); return false;">
    Cancel</a>
*/?>

</form>

